#include "ada_parm_data_set.h"
#include "main.h"

struct laser_adaptor_paramter configurable_parm;

struct master_conctrller_adaptor_paramter master_parm_set;

struct laser_adaptor_paramter slave_set_parm;

void slave_adaptor_parm_data_load(void)
{
  QString qstring_tmp;
  unsigned int i = adaptor_parm_set_summary.slave_id->lineedit->text().toInt();
  if ((1 <= i) && (SLAVE_NUM >= i))
  {
    i -= 1;
    adaptor_parm_set_summary.week1_mo1_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level1_mo1));
    adaptor_parm_set_summary.week1_mo2_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level1_mo2));
    adaptor_parm_set_summary.week1_fa1_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level1_fa1));
    adaptor_parm_set_summary.week1_fa2_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level1_fa2));

    adaptor_parm_set_summary.week2_mo1_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level2_mo1));
    adaptor_parm_set_summary.week2_mo2_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level2_mo2));
    adaptor_parm_set_summary.week2_fa1_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level2_fa1));
    adaptor_parm_set_summary.week2_fa2_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].level2_fa2));

    adaptor_parm_set_summary.strong_mo1_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].strong_mo1));
    adaptor_parm_set_summary.strong_mo2_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].strong_mo2));
    adaptor_parm_set_summary.strong_fa1_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].strong_fa1));
    adaptor_parm_set_summary.strong_fa2_current->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].strong_fa2));

    adaptor_parm_set_summary.mo1_current_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].mo1_up_limit));
    adaptor_parm_set_summary.mo2_current_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].mo2_up_limit));
    adaptor_parm_set_summary.fa_current_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].fa_up_limit));
    adaptor_parm_set_summary.can_address->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].can_address));

    adaptor_parm_set_summary.pd1_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].pd1_low_limit));
    adaptor_parm_set_summary.pd2_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].pd2_low_limit));
    adaptor_parm_set_summary.pd3_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].pd3_low_limit));
    adaptor_parm_set_summary.pd4_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].pd4_low_limit));

    adaptor_parm_set_summary.t1_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t1_low_limit));
    adaptor_parm_set_summary.t1_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t1_up_limit));
    adaptor_parm_set_summary.t2_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t2_low_limit));
    adaptor_parm_set_summary.t2_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t2_up_limit));
    adaptor_parm_set_summary.t3_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t3_low_limit));
    adaptor_parm_set_summary.t3_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t3_up_limit));
    adaptor_parm_set_summary.t4_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t4_low_limit));
    adaptor_parm_set_summary.t4_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].t4_up_limit));

    adaptor_parm_set_summary.envi_temperature_low_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].envi_temperature_low_limit));
    adaptor_parm_set_summary.envi_temperature_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].envi_temperature_up_limit));
    adaptor_parm_set_summary.envi_humidity_over_limit->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].envi_humidity_up_limit));
    adaptor_parm_set_summary.wave_length->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].wave_length));
    adaptor_parm_set_summary.expansion_module_id->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].expansion_module_id));
    adaptor_parm_set_summary.sn->lineedit->setText(qstring_tmp.setNum(adaptor_parm.laser_ada_parm[i].sn));

    adaptor_parm_set_summary.brake_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.brake);
    adaptor_parm_set_summary.power_comm_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.power_comm);
    adaptor_parm_set_summary.t1_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.t1);
    adaptor_parm_set_summary.t2_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.t2);
    adaptor_parm_set_summary.t3_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.t3);
    adaptor_parm_set_summary.t4_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.t4);
    adaptor_parm_set_summary.pd1_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.pd1);
    adaptor_parm_set_summary.pd2_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_1.part.pd2);

    adaptor_parm_set_summary.pd3_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.pd3);
    adaptor_parm_set_summary.pd4_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.pd4);
    adaptor_parm_set_summary.envi_temperature_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.envi_temperature);
    adaptor_parm_set_summary.envi_humidity_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.envi_humidity);
    adaptor_parm_set_summary.mo_current_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.mo);
    adaptor_parm_set_summary.fa_current_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.fa);
    adaptor_parm_set_summary.seq_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.seq);
    adaptor_parm_set_summary.master_comm_enable->set_clicked(adaptor_parm.laser_ada_parm[i].check_feature_2.part.master_comm);
  }
}

void fill_slave_set_parm(void)
{

  slave_set_parm.level1_mo1 = adaptor_parm_set_summary.week1_mo1_current->lineedit->text().toInt();
  slave_set_parm.level1_mo2 = adaptor_parm_set_summary.week1_mo2_current->lineedit->text().toInt();
  slave_set_parm.level1_fa1 = adaptor_parm_set_summary.week1_fa1_current->lineedit->text().toInt();
  slave_set_parm.level1_fa2 = adaptor_parm_set_summary.week1_fa2_current->lineedit->text().toInt();

  slave_set_parm.level2_mo1 = adaptor_parm_set_summary.week2_mo1_current->lineedit->text().toInt();
  slave_set_parm.level2_mo2 = adaptor_parm_set_summary.week2_mo2_current->lineedit->text().toInt();
  slave_set_parm.level2_fa1 = adaptor_parm_set_summary.week2_fa1_current->lineedit->text().toInt();
  slave_set_parm.level2_fa2 = adaptor_parm_set_summary.week2_fa2_current->lineedit->text().toInt();

  slave_set_parm.strong_mo1 = adaptor_parm_set_summary.strong_mo1_current->lineedit->text().toInt();
  slave_set_parm.strong_mo2 = adaptor_parm_set_summary.strong_mo2_current->lineedit->text().toInt();
  slave_set_parm.strong_fa1 = adaptor_parm_set_summary.strong_fa1_current->lineedit->text().toInt();
  slave_set_parm.strong_fa2 = adaptor_parm_set_summary.strong_fa2_current->lineedit->text().toInt();

  slave_set_parm.mo1_up_limit = adaptor_parm_set_summary.mo1_current_over_limit->lineedit->text().toInt();
  slave_set_parm.mo2_up_limit = adaptor_parm_set_summary.mo2_current_over_limit->lineedit->text().toInt();
  slave_set_parm.fa_up_limit = adaptor_parm_set_summary.fa_current_over_limit->lineedit->text().toInt();

  slave_set_parm.can_address = adaptor_parm_set_summary.can_address->lineedit->text().toInt();

  slave_set_parm.pd1_low_limit = adaptor_parm_set_summary.pd1_low_limit->lineedit->text().toInt();
  slave_set_parm.pd2_low_limit = adaptor_parm_set_summary.pd2_low_limit->lineedit->text().toInt();
  slave_set_parm.pd3_low_limit = adaptor_parm_set_summary.pd3_low_limit->lineedit->text().toInt();
  slave_set_parm.pd4_low_limit = adaptor_parm_set_summary.pd4_low_limit->lineedit->text().toInt();

  slave_set_parm.t1_low_limit = adaptor_parm_set_summary.t1_low_limit->lineedit->text().toInt();
  slave_set_parm.t1_up_limit = adaptor_parm_set_summary.t1_over_limit->lineedit->text().toInt();
  slave_set_parm.t2_low_limit = adaptor_parm_set_summary.t2_low_limit->lineedit->text().toInt();
  slave_set_parm.t2_up_limit = adaptor_parm_set_summary.t2_over_limit->lineedit->text().toInt();
  slave_set_parm.t3_low_limit = adaptor_parm_set_summary.t3_low_limit->lineedit->text().toInt();
  slave_set_parm.t3_up_limit = adaptor_parm_set_summary.t3_over_limit->lineedit->text().toInt();
  slave_set_parm.t4_low_limit = adaptor_parm_set_summary.t4_low_limit->lineedit->text().toInt();
  slave_set_parm.t4_up_limit = adaptor_parm_set_summary.t4_over_limit->lineedit->text().toInt();

  slave_set_parm.envi_temperature_low_limit = adaptor_parm_set_summary.envi_temperature_low_limit->lineedit->text().toInt();
  slave_set_parm.envi_temperature_up_limit = adaptor_parm_set_summary.envi_temperature_over_limit->lineedit->text().toInt();
  slave_set_parm.envi_humidity_up_limit = adaptor_parm_set_summary.envi_humidity_over_limit->lineedit->text().toInt();
  slave_set_parm.wave_length = adaptor_parm_set_summary.wave_length->lineedit->text().toInt();
  slave_set_parm.expansion_module_id = adaptor_parm_set_summary.expansion_module_id->lineedit->text().toInt();
  slave_set_parm.sn = adaptor_parm_set_summary.sn->lineedit->text().toInt();

  slave_set_parm.check_feature_1.part.brake = (adaptor_parm_set_summary.brake_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.power_comm = (adaptor_parm_set_summary.power_comm_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.t1 = (adaptor_parm_set_summary.t1_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.t2 = (adaptor_parm_set_summary.t2_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.t3 = (adaptor_parm_set_summary.t3_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.t4 = (adaptor_parm_set_summary.t4_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.pd1 = (adaptor_parm_set_summary.pd1_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_1.part.pd2 = (adaptor_parm_set_summary.pd2_enable->checkbox->isChecked()) ? (1) : (0);

  slave_set_parm.check_feature_2.part.pd3 = (adaptor_parm_set_summary.pd3_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.pd4 = (adaptor_parm_set_summary.pd4_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.envi_temperature = (adaptor_parm_set_summary.envi_temperature_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.envi_humidity = (adaptor_parm_set_summary.envi_humidity_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.mo = (adaptor_parm_set_summary.mo_current_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.fa = (adaptor_parm_set_summary.fa_current_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.seq = (adaptor_parm_set_summary.seq_enable->checkbox->isChecked()) ? (1) : (0);
  slave_set_parm.check_feature_2.part.master_comm = (adaptor_parm_set_summary.master_comm_enable->checkbox->isChecked()) ? (1) : (0);
}

void fill_master_set_parm(void)
{
  unsigned int mount_flag = 0;
  for (unsigned int i = 0; i < SLAVE_NUM; i++)
  {
    mount_flag |= (master_adaptor_set_parm_widget.slave_mount[i]->checkbox->isChecked() << i);
  }
  master_parm_set.mount_config = mount_flag;
  master_parm_set.check_feature.bit.brake = (master_adaptor_set_parm_widget.brake_enable->checkbox->isChecked()) ? (1) : (0);
  master_parm_set.check_feature.bit.commander_comm = (master_adaptor_set_parm_widget.commander_comm_enable->checkbox->isChecked()) ? (1) : (0);
}
